package jsyf.oa.web.migration;


import com.alibaba.fastjson.JSONObject;

import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.ExcelUtil;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.system.SystemFacade;

/**
 * 用户表迁移
 *
 * @author GUOQI
 * @date 2017-11-27 15:55:43
 */
@Api(value = "用户表迁移", description = "用户表迁移")
@Transactional(rollbackFor = Exception.class)
@Controller
@RequestMapping("/userMigration")
public class UserMigrationController {
    @Resource
    private SystemFacade systemFacade;

    /**
     * 新增用户
     */
    @ResponseBody
    @RequestMapping(value = "/saveUser.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "新增用户",
            notes = " 新增用户",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "无参数,需要将ssql导出excel表放在jsyf-oa/migration/res/下,执行此接口需修改文件名. (注意这里迁移的都是在职人员)", dataType = "String", paramType = "body")
    public void saveUser(HttpServletRequest request, HttpServletResponse response) {
        List<JSONObject> list = null;
        try {
            //list = ExcelUtil.ExportExcel("E:\\esh_oa\\p5_server\\shop\\jsyf-oa\\src\\main\\java\\jsyf\\oa\\web\\migration\\res\\liaoan.xlsx");
            for (int i = 0; i < list.size(); i++) {
                if ("0".equals(list.get(i).getString("del_flag"))){
                   //this.systemFacade.saveUser(list.get(i));
                }
            }
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond());
        } catch (Exception e) {
            e.printStackTrace();
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("迁移失败"));
        }
    }

}
